<template>
  <div class="topbar">
    <div class="wrap topbarWrap">
      <div class="l">欢迎来到叩丁狼积分商城</div>
      <ul class="r">
        <li>
          <img
            class="avatar"
            src="../assets/img/userImg.f8bbec5e.png"
            width="26"
            alt=""
          />
          用户名：{{ userStore.userObject.userInfo.nickName || "--" }}
        </li>
        <li>我的鸡腿：{{ userStore.userObject.userInfo.coin || "--" }}</li>
        <li>获取鸡腿</li>
        <li>叩丁狼官网</li>
        <li class="login-btn">
          <!-- {{
            userStore.isLogin
              ? "购物车" + userStore.userObject.cartTotal
              : "登录"
          }} -->
          <template v-if="userStore.token">
            <el-icon
              :size="22"
              style="vertical-align: middle; position: relative; bottom: 3px"
              ><ShoppingCart
            /></el-icon>
            购物车
            <span class="btn_color">
              {{ userStore.userObject.cartTotal }}
            </span>
          </template>
          <div v-else @click="loginStore.changeShowLogin">登录</div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reactive, toRefs, ref } from "vue";
import { useLoginStore } from "@/stores/login";
import { useUserStore } from "@/stores/user";
import { ShoppingCart } from "@element-plus/icons-vue";
const loginStore = useLoginStore();
const userStore = useUserStore();
console.log("重新加载");
</script>
<style lang="less" scoped>
.btn_color {
  width: 22px;
  height: 22px;
  line-height: 22px;
  display: inline-block;
  border-radius: 50%;
  background-color: #fd604d;
}
.topbar {
  height: 40px;
  line-height: 40px;
  background: #242b39;
  font-size: 14px;
  width: 100%;
  .topbarWrap {
    color: #fffefe;
    display: flex;
    justify-content: space-between;
    .r {
      li {
        float: left;
        margin-left: 20px;
        text-align: center;
        cursor: pointer;
        &.login-btn {
          width: 124px;
          height: 40px;
          background: #0a328e;
        }
      }
      .avatar {
        vertical-align: middle;
        border-radius: 50%;
      }
    }
  }
}
</style>
